package com.lanou3g.baidumusic.main.mainfragment;


import android.graphics.Color;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.lanou3g.baidumusic.R;
import com.lanou3g.baidumusic.main.mainactivity.BaseFragment;
import com.lanou3g.baidumusic.main.musicfragment.ksong.KSongFragment;
import com.lanou3g.baidumusic.main.musicfragment.listfragment.ListFragment;
import com.lanou3g.baidumusic.main.musicfragment.MusicFragmentAdapter;
import com.lanou3g.baidumusic.main.musicfragment.recommendfragment.RecommendFragment;
import com.lanou3g.baidumusic.main.musicfragment.songlistfragment.SongListFragment;
import com.lanou3g.baidumusic.main.musicfragment.videofragment.VideoFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class MusicFragment extends BaseFragment {

    private TabLayout tabLayout ;
    private MusicFragmentAdapter adapter ;
    private List<Fragment> fragments ;
    private ViewPager viewPager ;
    private String [] titles = {"推荐","歌单","榜单","视频","K歌"} ;



    public MusicFragment() {
        // Required empty public constructor
    }


    @Override
    public int setLayout() {
        return R.layout.fragment_music;
    }

    @Override
    public void initView(View view) {

        tabLayout = (TabLayout) view.findViewById(R.id.fragment_music_tl_tl);
        viewPager = (ViewPager) view.findViewById(R.id.fragment_music_vp_vp);

        fragments = new ArrayList<>();
        fragments.add(new RecommendFragment());
        fragments.add(new SongListFragment());
        fragments.add(new ListFragment());
        fragments.add(new VideoFragment());
        fragments.add(new KSongFragment());

    }

    @Override
    public void initData() {


        tabLayout.setTabTextColors(Color.BLACK , Color.parseColor("#88d7ff"));
        tabLayout.setBackgroundColor(Color.WHITE);
        tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
        tabLayout.setSelectedTabIndicatorColor(Color.parseColor("#88d7ff"));

        adapter = new MusicFragmentAdapter(getChildFragmentManager() , fragments);
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);


        for (int i = 0; i < titles.length; i++) {
            tabLayout.getTabAt(i).setText(titles[i]);
        }


//        for (int i = 0; i < adapter.getCount(); i++) {
//            View tabView = adapter.getTabView(i , getContext());
//
//            TabLayout.Tab tab = tabLayout.getTabAt(i);
//
//            tab.setCustomView(tabView);
//        }


    }
}
